// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import Vant from 'vant';
//import JSEncrypt from 'jsencrypt'

import 'vant/lib/index.css';

import '../static/css/ZxlCss.css';
import '../static/css/css.css';
import axios from 'axios'
import api from './api/http.js'
import {setCookie,getCookie,delCookie} from '@/api/cookie.js'
Vue.prototype.$cookieStore = {setCookie,getCookie,delCookie}
Vue.prototype.Trim = function(str)
{
return str.replace(/(^\s*)|(\s*$)/g, "");
}

import { Lazyload } from 'vant';

Vue.use(Lazyload);

//定义全局变量
Vue.prototype.$api = api;
Vue.use(Vant);
Vue.config.productionTip = false

/**/

// Vue.prototype.$encruption = function (obj) {
//   let encrypt = new JsEncrypt()
//   encrypt.setPublicKey('-----BEGIN PUBLIC KEY-----MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANa7VOggcvqlhFxlVWEsHR+NJ/mySRH4cCU73ho2ssou5RBJA81s/Bobj5MtDF1jqQPRKcYzrmsChDLjw5sG6nsCAwEAAQ==-----END PUBLIC KEY-----')  // 放置自己的公钥
//   return encrypt.encrypt(obj)
// }

// setCookie( 'userid' ,'1', 36000);
router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})


router.beforeEach((to, from, next) => {
  const type = to.meta.type
  // 判断该路由是否需要登录权限
  if(type === 'login'){
    if (getCookie("userid") == '' || getCookie("userid") == 'undefined' || getCookie("userid") == null){

      if(process.env.NODE_ENV=='production'){
        console.log(11111);

        setCookie('target_url',window.location.href, 36000);
        var auth_url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + process.env.AppID + '&redirect_uri=' + process.env.DOMAIN + 'Wechat&response_type=code&scope=snsapi_base&state=STATE&connect_redirect=1#wechat_redirect';
        window.location.replace(auth_url);

      }else{
          // cookie.set('userid',48);
         //setCookie( 'userid' ,'1', 36000);
      }

    }else{
      next()
    }
  }else{
    next()  // 确保一定要有next()被调用
  }
})


/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
